#!/usr/bin/env python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license.php 

"""
CGI interface to grab tweets from a given user and run the pipeline/model.
"""

import cgi
import cgitb  # enable for debugging
cgitb.enable()
import model


def main():
  print 'Content-type: text/html\n'
  user = cgi.FieldStorage().getvalue('user')
  num_tweets = int(cgi.FieldStorage().getvalue('tweets'))
  if user:
    print '<title>Processing Twitter user: %s</title>' % user
    usermodel = model.Model(user, num_tweets)
    usermodel.AssignTopics()
    usermodel.MakeHTML()
    print '<br>'
    print 'Report generated: <a href="../report/%s.html">%s</a>' % (user, user)
  else:
    print '<title>Error, no user specified!</title>'

if __name__ == "__main__":
  main()
